package com.naughty.userlogin02.controller;


import com.alibaba.fastjson.JSON;
import com.naughty.userlogin02.bean.QueryInfo;
import com.naughty.userlogin02.bean.Seehomework;
import com.naughty.userlogin02.dao.SeehomeworkDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class SeehomeworkController {

    @Autowired
    SeehomeworkDao seehomeworkDao;

    @CrossOrigin
    @RequestMapping("/allSeeHomeworkT")
    //未提交
    public String getSeeHomeworkTList(String nowtname,String nowtpwd,QueryInfo queryInfo) {

        System.out.println("hhhhhhhhhhhh");
        System.out.println(nowtname);
        System.out.println("hhwwwwww");
        System.out.println(nowtpwd);

        int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
        System.out.println(queryInfo);
        int numbers = seehomeworkDao.getSeehomeworkCounts(nowtname);// 获取数据总数
        System.out.println("aaaaaa");
        System.out.println(numbers);
        List<Seehomework> users = seehomeworkDao.getAllSeehomeworkT(nowtname,nowtname,pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers", numbers);
        res.put("data", users);
        System.out.println("总条数：" + numbers);
        String users_json = JSON.toJSONString(res);
        System.out.println("pppppp");
        System.out.println(users_json);
        return users_json;
    }


    //已批改
    @RequestMapping("/allSeeHomeworkS")
    public String getSeeHomeworkSList(String nowtname,String nowtpwd,QueryInfo queryInfo) {

        System.out.println("hhhhhhhhhhhh");
        System.out.println(nowtname);
        System.out.println("hhwwwwww");
        System.out.println(nowtpwd);

        int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
        System.out.println(queryInfo);
        int numbers = seehomeworkDao.getSeehomeworkCountsS(nowtname);// 获取数据总数
        System.out.println("aaaaaa");
        System.out.println(numbers);
        List<Seehomework> users = seehomeworkDao.getAllSeehomeworkS(nowtname,nowtname,pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers", numbers);
        res.put("data", users);
        System.out.println("总条数：" + numbers);
        String users_json = JSON.toJSONString(res);
        System.out.println("pppppp");
        System.out.println(users_json);
        return users_json;
    }

    //等待批改
    @RequestMapping("/allSeeHomeworkD")
    public String getSeeHomeworkDList(String nowtname,String nowtpwd,QueryInfo queryInfo) {

        System.out.println("hhhhhhhhhhhh");
        System.out.println(nowtname);
        System.out.println("hhwwwwww");
        System.out.println(nowtpwd);

        int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
        System.out.println(queryInfo);
        int numbers = seehomeworkDao.getSeehomeworkCountsD(nowtname);// 获取数据总数
        System.out.println("aaaaaa");
        System.out.println(numbers);
        List<Seehomework> users = seehomeworkDao.getAllSeehomeworkD(nowtname,nowtname,pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers", numbers);
        res.put("data", users);
        System.out.println("总条数：" + numbers);
        String users_json = JSON.toJSONString(res);
        System.out.println("pppppp");
        System.out.println(users_json);
        return users_json;
    }


    //对于学生
    @RequestMapping("/allSeeHomeworkStu")
    public String getSeeHomeworkStuList(String nowtname,String nowtpwd,QueryInfo queryInfo) {

        System.out.println("hhhhhhhhhhhh");
        System.out.println(nowtname);
        System.out.println("hhwwwwww");
        System.out.println(nowtpwd);

        int pageStart = (queryInfo.getPageNum() - 1) * queryInfo.getPageSize();
        System.out.println(queryInfo);
        int numbers = seehomeworkDao.getSeehomeworkCountsStu(nowtname);// 获取数据总数
        System.out.println("aaaaaa");
        System.out.println(numbers);
        List<Seehomework> users = seehomeworkDao.getAllSeehomeworkStu(nowtname,nowtname,pageStart,queryInfo.getPageSize());
        HashMap<String, Object> res = new HashMap<>();
        res.put("numbers", numbers);
        res.put("data", users);
        System.out.println("总条数：" + numbers);
        String users_json = JSON.toJSONString(res);
        System.out.println("pppppp");
        System.out.println(users_json);
        return users_json;
    }


}
